package com.hongkzh.www.adv.controller;

import com.hongkzh.www.adv.service.MediaService;
import com.hongkzh.www.conmon.ReqResponse;
import com.hongkzh.www.swagger.annotation.*;
import com.jfinal.core.Controller;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;

import java.util.ArrayList;
import java.util.List;

/**
 * @author martins
 */
@Api(tag = "mediaAdv", description = "自媒体广告")
public class MediaAdvController extends Controller {
    MediaService mediaService=new MediaService();

    @ApiOperation(url = "/v1/mediaAdv/getCarouselList", tag = "mediaAdv", httpMethod = "post",description = "获取自媒体主页轮播图列表")
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "{ imgSrc 图片地址 ,imgLinks 图片链接 imgRank 图片排序 background 背景 }"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getCarouselList(){
        ReqResponse<List<Record>> r=new ReqResponse();
        List<Record>  record= mediaService.getCarouselList();
        r.setData(record);
        renderJson(r);
    }
    @ApiOperation(url = "/v1/mediaAdv/userCategoryList", tag = "mediaAdv", httpMethod = "post",description = "通过当前登录用户id 获取分类信息")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = false, dataType = "string"),
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "{ imgSrc 图片地址 ,categoryId 分类id imgRank 图片排序   }"),
                    @ResponseHeader(name="msg",description = "失败原因") })
    })
    public void userCategoryList(){
        String loginId=getPara("loginUid");
        ReqResponse<List<Record>> r=new ReqResponse();
        List<Record>  record=new ArrayList<>();
        if(StrKit.notBlank(loginId)) {
            record = mediaService.userCategoryList(loginId);
        }
        if(null==record||record.size()==0){
            record= mediaService.categoryList();
        }
        r.setData(record);
        renderJson(r);
    }

    @ApiOperation(url = "/v1/mediaAdv/getTop10List", tag = "mediaAdv", httpMethod = "post",description = "获取自媒体主页top10列表")
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "{ coverImgSrc 图片地址 ,title 标题 , playCount 播放总数 , integral 乐币 , userId 用户id , id 视频id  }"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getTop10List(){
        ReqResponse<List<Record>> r=new ReqResponse();
        List<Record>  record= mediaService.getTop10List();
        r.setData(record);
        renderJson(r);
    }




    @ApiOperation(url = "/v1/mediaAdv/getHotAdvList", tag = "mediaAdv", httpMethod = "post",description = "获取自媒体人气分页信息")

    @Params({
            @Param(name = "pageNumber", description = "页码", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "totalRow 总行数  pageNumber第几页 firstPage 是否第一页 lastPage 是否最后一页 totalPage 总页数 pageSize每页条数  list[{ headImg 头像   uid 自媒体或者企业id uName 用户名称 id 视频id coverImgSrc 图片地址 coverLink 图片链接  imgSrc 视频地址 ,imgLinks 视频链接 imgRank 图片排序 title 标题 imgNote 副标题  playCount 播放数 provinceName 省名称   cityName 城市名称  integral 乐币 }]"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getHotAdvList(){
        int pageNumber=getParaToInt("pageNumber");
        ReqResponse<Page<Record>> r=new ReqResponse();
        Page<Record> record= mediaService.getHotAdvList(pageNumber);
        r.setData(record);
        renderJson(r);
    }
    @ApiOperation(url = "/v1/mediaAdv/getNearbyAdvList", tag = "mediaAdv", httpMethod = "post",description = "获取自媒体人气分页信息")

    @Params({
            @Param(name = "latitude", description = "纬度", required = true, dataType = "string"),
            @Param(name = "longitude", description = "经度", required = true, dataType = "string"),
            @Param(name = "pageNumber", description = "页码", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "totalRow 总行数  pageNumber第几页 firstPage 是否第一页 lastPage 是否最后一页 totalPage 总页数 pageSize每页条数  list[{ headImg 头像   uid 自媒体或者企业id uName 用户名称 id 视频id coverImgSrc 图片地址 coverLink 图片链接  imgSrc 视频地址 ,imgLinks 视频链接 imgRank 图片排序 title 标题 imgNote 副标题  playCount 播放数  distance 距离 integral 乐币  }]"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getNearbyAdvList(){
        double latitude=Double.parseDouble(getPara("latitude"));
        double longitude=Double.parseDouble(getPara("longitude"));
        int pageNumber=getParaToInt("pageNumber");
        ReqResponse<Page<Record>> r=new ReqResponse();

        Page<Record> record= mediaService.getNearbyAdvList(latitude,longitude,pageNumber);
        r.setData(record);
        renderJson(r);
    }
}
